/*
 * @Description: 
 * @Author: changqing
 * @Date: 2021-08-30 19:44:10
 * @LastEditTime: 2021-08-30 19:45:16
 * @LastEditors: changqing
 * @Usage: 
 */
var { timer, interval,range,from,Subject } = require('rxjs'); 
var {take,map, multicast,publish,refCount,share} = require('rxjs/operators');

//share 基本上就是 multicast(new Subject()) 与 refCount() 的组合，也可以看成是publish()与refCount()的组合。


const source = interval(1000)
  .pipe(
        map((x) => {
            console.log('Processing: ', x);
            return x*x;
        }),
        share()
);

source.subscribe(x => console.log('subscription 1: ', x));
source.subscribe(x => console.log('subscription 1: ', x));

// Logs:
// Processing:  0
// subscription 1:  0
// subscription 1:  0
// Processing:  1
// subscription 1:  1
// subscription 1:  1
// Processing:  2
// subscription 1:  4
// subscription 1:  4
// Processing:  3
// subscription 1:  9
// subscription 1:  9
// ... and so on